<xsl:stylesheet version="2.0" xmlns:foo="http://something" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="foo">

	<!--Translation function, replace '%s'-->
	<xsl:function name="foo:translate" as="xs:string">
		<xsl:param name="search" as="xs:string"/>
		<xsl:param name="doc" as="node()*"/>
		<xsl:variable name="match" select="$doc//message[matches(string($search), concat('^',replace(replace(replace(replace(string(./@id), '\.', '\\.'), '\*', '\\*'), '%s', '.*'), '\?', '\\?'), '$'))]"/>
		<xsl:analyze-string select="$search"
       regex="{concat('^',replace(replace(replace(replace(string($match/@id), '\.', '\\.'), '\*', '\\*'), '%s', '(.*)'), '\?', '\\?'), '$')}">
			<xsl:matching-substring>
				<xsl:value-of select="replace($match, '%s', regex-group(1))"/>
			</xsl:matching-substring>
		</xsl:analyze-string>
	</xsl:function>
	
</xsl:stylesheet>